<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html>
<html  lang="zh">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
    <title>登录系统</title>
    <link href="static/css/bootstrap.min.css" rel="stylesheet"/>
    <link href="static/css/font-awesome.min.css" rel="stylesheet"/>
    <link href="static/css/style.css" rel="stylesheet"/>
    <link href="static/css/login.min.css" rel="stylesheet"/>
    <link href="static/ruoyi/css/ry-ui.css" rel="stylesheet"/>
    <link rel="shortcut icon" href="favicon.ico"/>
    <script>
        if(window.top !== window.self){window.top.location = window.location};
    </script>
    <link rel="stylesheet" href="static/js/jconfirm/jquery-confirm.min.css">
</head>
<body class="signin">
    <div class="signinpanel">
        <div class="row">
            <div class="col-sm-7">
                <div class="signin-info">
                    <div class="m-b"></div>
                    <h4>欢迎使用 <strong> 后台管理系统</strong></h4>
                    <ul class="m-b">
                        <li><i class="fa fa-arrow-circle-o-right m-r-xs"></i> 绿茶</li>
                        <li><i class="fa fa-arrow-circle-o-right m-r-xs"></i> 红茶</li>
                        <li><i class="fa fa-arrow-circle-o-right m-r-xs"></i> 黑茶</li>
                        <li><i class="fa fa-arrow-circle-o-right m-r-xs"></i> 白茶</li>
                    </ul>
                    <strong>还没有账号？ <a href="register.jsp">立即注册&raquo;</a></strong><br/>
                    <strong>忘记了密码？ <a href="findpwd.jsp">找回密码&raquo;</a></strong><br/>
                    <strong>账号被冻结？ <a class="application">申请解冻&raquo;</a></strong>
                </div>
            </div>
            <div class="col-sm-5">
                <form id="loginFrom" style="color: #0a0a0a" >
                    <h4 class="no-margins">登录：</h4>
                    
                    <input type="email" id="email" name="email" class="form-control"  placeholder="邮箱"/>
                    <input type="password" id="password" name="password" class="form-control" placeholder="密码"/>
					<!-- <div class="row m-t">
						<div class="col-xs-5">
						    <input type="text" id="code" name="code" class="form-control" placeholder="验证码">
						</div>
						<div class="col-xs-6">
                            <button type="button" class="btn btn-sm btn-success" onclick="Login.getCode();">点击发送验证码</button>
						</div>
					</div> -->
					
                    <button class="btn btn-success btn-block" type="button" onclick="login();" data-loading="正在验证登录，请稍后...">登录</button>
                </form>                
            </div>
        </div>
        <div class="signup-footer">
            <div class="pull-left">
                Copyright © 2019. 蓝点工作室 All rights reserved.  <br>
            </div>
        </div>
    </div>

    <input id="response_code" type="hidden"/>

<!-- 全局js -->
<script src="static/js/jquery.min.js"></script>
<script src="static/js/bootstrap.min.js"></script>
<script src="static/js/jconfirm/jquery-confirm.min.js"></script>
<!-- 验证插件 -->
<script src="static/ajax/libs/validate/jquery.validate.min.js"></script>
<script src="static/ajax/libs/validate/messages_zh.min.js"></script>
<script src="static/ajax/libs/layer/layer.min.js"></script>
<script src="static/ajax/libs/blockUI/jquery.blockUI.js"></script>
<script src="static/ruoyi/js/ry-ui.js"></script>
<script>
	//获取项目根目录
	function getRootPath(){
		let href = window.document.location.href;
		let pathName = window.document.location.pathname;
		let index = href.indexOf(pathName);
		let localhost = href.substring(0,index);
		let project = pathName.substring(0,(pathName.substr(1).indexOf('/'))+1);
			
		return (localhost+project);
	}
	
	let rootPath = getRootPath();

    let Login = {
        loginCheck : function () {
            let password = $("#password").val();
            if(password === '' || password == null){
                $.modal.msg("密码不能为空");
                return false;
            }
            return true;
        }
    }
    
    function login(){
    	if(Login.loginCheck()){
    		let email = $("#email").val();
            let password = $("#password").val();

            $.ajax({
                url: rootPath+"/login.do",
                type:"POST",
                dataType:"json",
                data : {
                    email : email,
                    password : password
                },
                success : function (response) {
                    if(response.RESULT === "failed"){
                    	$.modal.alert(response.message);
                    	$("#response_code").val("");
                    }else{
                    	window.location.href = "index.jsp";
                    }                    	
                }
            });
    	}
    }
        
    
  	//解冻申请
    $('.application').on('click', function () {

        layer.prompt({title: '输入申请邮箱，并确认', formType: 0}, function(email, index){

            let reg = /^([a-zA-Z]|[0-9])(\w|\-)+@[a-zA-Z0-9]+\.([a-zA-Z]{2,4})$/;
            if(!reg.test(email)){
                $.modal.alert("邮箱格式不正确");
                return false;
            }
            
            //验证用户状态和邮箱是否符合条件
      		$.ajax({
      			type:"GET",
                url: rootPath+"/get/user.do?email="+email,
                dataType:"json",
                error : function(){
                	$.modal.alert("请求不可达...");
                },
                success:function (response) {
    				let user = response.user;
    				if(user == null){
    	            	$.modal.alert("当前用户不存在");
    	            	return false;
    	            }
    	            
    	            if(user.status != 0){
    	            	$.modal.alert("当前用户未被冻结，无需解冻");
    	                return false;
    	            }
    	            
    	      		layer.close(index);

    	            layer.prompt({title: '输入申请理由，并确认', formType: 2}, function(content, index){
    	                //插入一条解冻申请
    	                $.ajax({
    			  			type:"post",
    			            url: rootPath+"/insert/thaw/application.do",
    			            data:{
    			            	email:email,
    			            	content:content
    			            },
    			            dataType:"json",
    			            success:function (response) {
    			            	layer.close(index);
    							$.modal.alert(response.message);
    			            }
    			  		});
    	                
    	            });
    	            
                }
      		});
            
        });
    });
  	  	
    
    /* let countdown = 60;
    function setTime(obj) {
        if (countdown === 0) {
            $(obj).prop('disabled', false);
            $(obj).text("点击获取验证码");
            this.countdown = 60;//60秒过后button上的文字初始化,计时器初始化;
            return;
        } else {
            $(obj).prop('disabled', true);
            $(obj).text("("+countdown+"s)后重新发送") ;
            countdown--;
        }
        setTimeout(function() { setTime(obj) },1000) //每1000毫秒执行一次
    } */
</script>
</body>
</html>